home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10119 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  995 b 

  1. Path: gambier.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP NEEDED..Please no Sermons
  5. Date: 15 Mar 1996 10:07:54 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4icblqINN79k@gambier.ugrad.cs.ubc.ca>
  8. References: <4i7th3$c9@newsbf02.news.aol.com> <4i9elsINN7ss@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: gambier.ugrad.cs.ubc.ca
  10.  
  11. In article <4i9elsINN7ss@keats.ugrad.cs.ubc.ca>,
  12. Kazimir Kylheku <c2a192@ugrad.cs.ubc.ca> goofed:
  13.  >#include <time.h>
  14.  >#include <stdio.h>
  15.  >.
  16.  >.
  17.  >.
  18.  >    char str[20];
  19.  >
  20.  >    strftime(str,20,"%H.%M.%S",localtime(NULL));
  21.  >
  22.  >    puts(str);
  23.  
  24. localtime() can't deal with a NULL argument properly, unlike time(). So the
  25. above should be:
  26.  
  27.     char str[20];
  28.     time_t t = time(NULL);
  29.  
  30.     /* ... or a statement (void) time(&t); */
  31.  
  32.     strftime(str, 20, "%H.%M.%S", localtime(&t));
  33.  
  34. Thanks to Gordin burditt <gordon@sneaky.lerctr.org> for pointing out the
  35. problem.
  36. -- 
  37.  
  38.